package abcy.cloud.syscoreserver.controller;

import abcy.cloud.blogcommon.resp.ResponseEntity;
import abcy.cloud.syscoreserver.dto.req.SysRoleAddReqDto;
import abcy.cloud.syscoreserver.dto.req.SysRoleSelectReqDto;
import abcy.cloud.syscoreserver.dto.resp.SysRoleSelectRespDto;
import abcy.cloud.syscoreserver.services.SysRoleService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping(value = "/sysrole")
public class SysRoleController {

    @Resource
    private SysRoleService sysRoleService;

    @PostMapping(value = "selectRolesForPage")
    public ResponseEntity selectRolesForPage(@RequestBody SysRoleSelectReqDto sysRoleSelectReqDto) {
        PageInfo<SysRoleSelectRespDto> pageInfo = sysRoleService.selectRolesForPage(sysRoleSelectReqDto);
        return ResponseEntity.success(pageInfo);
    }

    @PostMapping(value = "/addRole")
    public ResponseEntity addRole(@RequestBody SysRoleAddReqDto sysRoleAddReqDto) {
        sysRoleService.addRole(sysRoleAddReqDto);
        return ResponseEntity.success(sysRoleAddReqDto);
    }

    @PostMapping(value = "/selectRolesByUserId")
    public Map<String, Object> selectRolesByUserId(@RequestBody Map<String, Object> map) {
        return sysRoleService.selectRolesByUserId(map);
    }
}
